*****************************************************************
***                  Log AkelPad plugin v3.1                  ***
*****************************************************************

2012 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)


*** Description ***

Watch logs or capture application output in real-time.


*** Functions ***

Log::Watch
Watch log.

Log::Output
Capture output.

Log::Settings
Settings dialog.


*** External call Log::Output ***

Call("Log::Output", 1, "PROGRAM", "WORKDIR", "REPATTERN", "RETAGS", INPUTCODEPAGE, OUTPUTCODEPAGE, FLAGS)
  Parameters:
    1
      Execute application and capture output.
    "PROGRAM"
      File for execution.
    "WORKDIR"
      Working directory.
    "REPATTERN"
      Regular expression pattern. Applied to each output line to jump to the text from the panel.
    "RETAGS"
      Pattern matches map.
        /FILE=$1         file to jump.
        /GOTOLINE=$2:$3  line and column to jump.
        /GOTOBYTE=$2     byte offset to jump.
        /GOTOCHAR=$2     character offset to jump.
        /FRAME=$1        frame data handle to jump.
    INPUTCODEPAGE
      Codepage of the input text for executed file.
      If -1, codepage will be autodetected.
      If -2 or not specified, codepage from plugin settings will be used.
    OUTPUTCODEPAGE
      Codepage of the output text from executed file.
      If -1, codepage will be autodetected.
      If -2 or not specified, codepage from plugin settings will be used.
    FLAGS (sum of the following):
         1  Don't show output panel.
         2  Hide input line.
         4  Save all documents before execution.
         8  Append text to the end.
        16  No scroll to the end.
        32  Wrap lines.

      4096  Source input - selection or all document if selection is empty.
      8192  Source input - all document.
     16384  Source input - selection.
            By default: source input isn't used.

   1048576  Output target - selection or all document if selection is empty.
   2097152  Output target - current document.
   4194304  Output target - current document selection.
   8388608  Output target - new tab.
            By default: output target - output panel.

  Example (output to output panel):
    Call("Log::Output", 1, `tracert akelpad.sourceforge.net`)
  Example (output to selection without output panel):
    Call("Log::Output", 1, `ipconfig`, "", "", "", -1, -1, 1048577)
  Example (batch file execution for compilation):
    Call("Log::Output", 1, `"%d\Build.cmd" /S`, "%d", "^(([^\(:]+(:[\\/])?)+)[\(:](\d+)([,:](\d+))?[\):]", "/FILE=$1 /GOTOLINE=$4:$6")

Call("Log::Output", 2, *WINDOW)
  Parameters:
    2
      Get text output window handle. Use with Scripts plugin.
    *WINDOW
      Pointer to a variable, that receives text output window handle.
  Example:
    WScript.Echo(GetOutputWindow());

    function GetOutputWindow()
    {
      var lpWindow;
      var nWindow=0;

      if (lpWindow=AkelPad.MemAlloc(_X64?8:4 /*sizeof(HWND)*/))
      {
        AkelPad.Call("Log::Output", 2, lpWindow);
        nWindow=AkelPad.MemRead(lpWindow, 2 /*DT_QWORD*/);
        AkelPad.MemFree(lpWindow);
      }
      return nWindow;
    }

Call("Log::Output", 3, *EXECSTATE, *PLUGINTHREAD, *PROCESSHANDLE, *PROCESSID)
  Parameters:
    3
      Get information about the current executed application. Use with Scripts plugin.
    *EXECSTATE
      Pointer to a variable, that receives execution state. Can be NULL.
      Sum of the following:
        0  Idle state.
        1  Execution command received.
        2  Plugin thread created, from which application will be executed.
        4  Application is executed and working.
    *PLUGINTHREAD
      Pointer to a variable, that receives plugin thread handle from which application was executed. Can be NULL.
    *PROCESSHANDLE
      Pointer to a variable, that receives process handle of the executed application. Can be NULL.
    *PROCESSID
      Pointer to a variable, that receives process id of the executed application. Can be NULL.
  Example:
    WScript.Echo(GetExecState());

    function GetExecState()
    {
      var lpState;
      var nState=0;

      if (lpState=AkelPad.MemAlloc(4 /*sizeof(DWORD)*/))
      {
        AkelPad.Call("Log::Output", 3, lpState);
        nState=AkelPad.MemRead(lpState, 3 /*DT_DWORD*/);
        AkelPad.MemFree(lpState);
      }
      return nState;
    }

Call("Log::Output", 4, "TEXT", TEXTLEN, APPEND, CODEPAGE)
  Parameters:
    4
      Set/Add text in the output panel. Use with Scripts plugin.
    "TEXT"
      Text for insertion. String type ANSI.
    TEXTLEN
      Text length (default is -1). If -1, text string is terminated with NULL symbol.
    APPEND (one of the following):
      0 Replace all text in the output panel.
      1 Add text in the output panel (by default).
    CODEPAGE
      Text codepage. By default ANSI system codepage is used.

Call("Log::Output", 5, "TEXT", TEXTLEN, APPEND)
  Same as 4, but "TEXT" has string type Unicode.


*** External call Log::Settings ***

Call("Log::Settings", 1, PAGE)
  Parameters:
    1
      Open settings dialog at specified page.
    PAGE
      Zero based page index.
